#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
from tld import get_tld
reload(sys)
sys.setdefaultencoding('utf-8')

for i in sys.stdin:
    t=i.strip().split('\t')
    if len(t)==7:
        cid,sid,session,pv,nasid,referer,urls=t
        if urls and len(urls)>0:
            eps=urls.strip().split(',')
            if referer and referer.startswith('http'):
                referer=get_tld(referer,fail_silently=True)
                if not referer:
                    referer='直接输入网址或书签'
            else:
                referer='直接输入网址或书签'
                
            if len(eps)==1:
                if eps[0].startswith('http'):
                    page=get_tld(eps[0],fail_silently=True,as_object=True)
                    if page:
                        current='%s.%s' % (page.subdomain,page.tld)
                        print '\t'.join(map(str,[cid,sid,session,nasid,pv,referer,current,'离开网站']))
            elif len(set(eps[:2]))==2:
                if eps[0] and eps[1] and eps[0].startswith('http') and eps[1].startswith('http'):
                    page1,page2=get_tld(eps[0],fail_silently=True,as_object=True),get_tld(eps[1],fail_silently=True)
                    if page1 and page2:
                        current='%s.%s' % (page1.subdomain,page1.tld)
                        print '\t'.join(map(str,[cid,sid,session,nasid,pv,referer,current,page2]))   
            
                 